package com.example.schoolhelp.util;

import android.content.Context;
import android.media.MediaPlayer;

import com.example.schoolhelp.R;


/**
 * Created by user on 2017/4/20.
 */

public class MediaPlayFactory {
    private MediaPlayFactory instance;
    private MediaPlayer player;
    private String path_reset_tip = "file:////android_assets/ipc/voice_device_reset_step1.mp3";

    public MediaPlayFactory() {
        player = new MediaPlayer();
    }



    public void playAlarm(Context context) {
        try {
            if (player == null) {
            }
            player = MediaPlayer.create(context, R.raw.alarm);//create不能调用prepare
//            AssetManager assets = context.getAssets();
//            AssetFileDescriptor assetFileDescriptor = assets.openFd("ipc/voice_device_reset_step1.mp3");
//            player.setDataSource(assetFileDescriptor.getFileDescriptor());
//            player.prepare();
            player.setLooping(false);
            player.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void pausePlay() {
        if (player == null) {
            return;
        }
        if (player.isPlaying()) {
            player.pause();
        }
    }

    public void releasePlayer() {
        if (player != null) {
            player.release();
        }

    }
}
